﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using kxcxw.Data.Common;
using kxcxw.Data.Entities;
using System.Web.Security;
using kxcxw.Data;

namespace KXCXW.Web.Controllers
{
    public class ContentController : Controller
    {
        private static KXCXWDBContext db = new KXCXWDBContext();

        // GET: /Content/
        public ActionResult About()
        {
            return View();
        }
        public ActionResult ContactUs()
        {
            return View();
        }
        public ActionResult CooperativeAd()
        {
            return View();
        }
        public ActionResult CopyrightST()
        {
            return View();
        }

        public ActionResult Feedback()
        {
            
            Feedback fb = new Feedback();
            MembershipUser user = Membership.GetUser();
            if (user != null && user.ProviderUserKey != null)
            {
                //fb.UserID = user.ProviderUserKey.ToString();
                fb.UserName = user.UserName;
                fb.ContactInfo = user.Email;
            }
            return View(fb);
        }

        [HttpPost]
        public ActionResult ReleaseFeedback(Feedback fb)
        {
            Feedback fbAdded = null;
            if (ModelState.IsValid)
            {
                MembershipUser user = Membership.GetUser();
                fb.CreateDate = DateTime.Now;
                //
                if (user!=null && user.ProviderUserKey !=null)
                {
                    fb.UserID = user.ProviderUserKey.ToString();
                }
                fbAdded= db.Feedbacks.Add(fb);

                db.SaveChanges();
                return View("Feedback", fbAdded);
            }

            return View("Feedback", fb);
        }//fun
    }
}
